package com.gitee.jmliu1983.test;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson2.JSONObject;
import com.gitee.jmliu1983.analysis.ParamHistoryMerger;

public class AnalysisTest {

//	@Test
	public void TestParamHistoryMerger() {
		ParamHistoryMerger merger = ParamHistoryMerger.getInstance();
		List<JSONObject> spotsPage1 = new ArrayList<JSONObject>();
		List<JSONObject> spotsPage2 = new ArrayList<JSONObject>();
		List<JSONObject> spotsPage3 = new ArrayList<JSONObject>();
		List<JSONObject> spotsPage4 = new ArrayList<JSONObject>();

//		JSONObject spotBase = new JSONObject();
//		spotBase.put("spot_drawing", "8WD_813_021____0210_A99_0007_R");
//		spotBase.put("datetime", "2024-09-13 08:35:50");
//		spotBase.put("current", "8930");

//		JSONObject spot = spotBase.clone();
		
		// 生成page1数据
		String[] spotDrawings = { "S1", "S1", "S1", "S2", "S1", "S1", "S2", "S1", "S2", "S1" };
		String[] dts= {
				"2024-09-13 08:35:00",
				"2024-09-13 08:35:10",
				"2024-09-13 08:35:20",
				"2024-09-13 08:35:30",
				"2024-09-13 08:35:40",
				"2024-09-13 08:35:50",
				"2024-09-13 08:34:10",
				"2024-09-13 08:34:20",
				"2024-09-13 08:34:30",
				"2024-09-13 08:34:40",
				};
		Integer[] currents= {1,1,1,2,2,2,1,1,1,1};
		for(int i=0;i<spotDrawings.length;i++) {
			JSONObject spot = new JSONObject();
			spot.put("spot_drawing", spotDrawings[i]);
			spot.put("datetime", dts[i]);
			spot.put("current", currents[i].toString())			;
			spotsPage1.add(spot);
		}
		
		//生成page2数据
		spotDrawings = new String[] {"S1", "S2", "S1", "S2", "S1", "S1", "S2", "S1", "S2", "S1"} ;
		dts=new String[] {
				"2024-09-13 08:36:00",
				"2024-09-13 08:36:10",
				"2024-09-13 08:37:20",
				"2024-09-13 08:37:30",
				"2024-09-13 08:37:40",
				"2024-09-13 08:36:50",
				"2024-09-13 08:37:10",
				"2024-09-13 08:36:20",
				"2024-09-13 08:36:30",
				"2024-09-13 08:36:40",
				};
		currents= new Integer[] {1,2,1,2,2,2,1,1,1,1};
		for(int i=0;i<spotDrawings.length;i++) {
			JSONObject spot = new JSONObject();
			spot.put("spot_drawing", spotDrawings[i]);
			spot.put("datetime", dts[i]);
			spot.put("current", currents[i].toString())			;
			spotsPage2.add(spot);
		}		
		//生成page3数据
		spotDrawings = new String[] {"S1", "S1", "S1", "S2", "S1", "S1", "S2", "S1", "S2", "S1"} ;
		dts=new String[] {
				"2024-09-13 08:39:00",
				"2024-09-13 08:39:10",
				"2024-09-13 08:39:20",
				"2024-09-13 08:39:30",
				"2024-09-13 08:39:40",
				"2024-09-13 08:39:50",
				"2024-09-13 08:38:10",
				"2024-09-13 08:38:20",
				"2024-09-13 08:38:30",
				"2024-09-13 08:38:40",
				};
		currents= new Integer[] {1,1,1,2,2,2,1,2,1,1};
		for(int i=0;i<spotDrawings.length;i++) {
			JSONObject spot = new JSONObject();
			spot.put("spot_drawing", spotDrawings[i]);
			spot.put("datetime", dts[i]);
			spot.put("current", currents[i].toString())			;
			spotsPage3.add(spot);
		}
		System.out.println('[');
		merger.setConf("spot_drawing", "datetime", "current", "yyyy-MM-dd HH:mm:ss");
		merger.feedItems(spotsPage1);
		merger.feedItems(spotsPage2);
		merger.feedItems(spotsPage3);

		List<JSONObject> finalTimeline = merger.getFinalMergedResult();
		System.out.println(']');
		System.out.println("FINAL:");
		System.out.println(finalTimeline.toString());
	}
}
